﻿namespace Model.DTO
{
    /// <summary>
    /// 响应对象
    /// </summary>
    public class ReturnJson
    {
        /// <summary>
        /// 响应状态
        /// </summary>
        public bool State { get; set; }
        /// <summary>
        /// 响应消息
        /// </summary>
        public string Message { get; set; }
        /// <summary>
        /// 响应码
        /// </summary>
        public int Code { get; set; }
        /// <summary>
        /// 成功
        /// </summary>
        /// <returns></returns>
        public ReturnJson Success(int code = 1, bool state = true, string message = "成功")
        {
            Code = code; State = state; Message = message;
            return this;
        }
        /// <summary>
        /// 失败
        /// </summary>
        /// <returns></returns>
        public ReturnJson Fail(int code = 0, bool state = false, string message = "失败")
        {
            Code = code; State = state; Message = message;
            return this;
        }
        /// <summary>
        /// 未授权
        /// </summary>
        /// <returns></returns>
        public ReturnJson Unauthorized(int code = 3, bool state = false, string message = "未授权")
        {
            Code = code; State = state; Message = message;
            return this;
        }
        /// <summary>
        /// 为空
        /// </summary>
        /// <returns></returns>
        public ReturnJson Null(int code = 4, bool state = true, string message = "成功")
        {
            Code = code; State = state; Message = message;
            return this;
        }
        /// <summary>
        /// 异常
        /// </summary>
        /// <returns></returns>
        public ReturnJson Error(int code = -1, bool state = false, string message = "异常")
        {
            Code = code; State = state; Message = message;
            return this;
        }
    }
    /// <summary>
    /// 响应T对象
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class ReturnJson<T> : ReturnJson
    {
        /// <summary>
        /// 泛型数据类
        /// </summary>
        public T Data { get; set; }
        /// <summary>
        /// 成功
        /// </summary>
        /// <param name="t"></param>
        /// <param name="code"></param>
        /// <param name="state"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public ReturnJson Success(T t, int code = 1, bool state = true, string message = "成功")
        {
            base.Success(code,state,message);
            this.Data = t;
            return this;
        }
    }
}

